import 'package:sports_new/utils/date_time_utils.dart';
import 'package:sports_new/utils/utils.dart';

import '../../match/expert_views_entity.dart';
import '../plan_Info_entity.dart';

class PlanFormDetail {
  bool? expertFocus;
  String? expertId;
  String? expertLogo;
  String? expertName;
  IssueInfo? issueInfo;

  PlanFormDetail({this.expertFocus, this.expertId, this.expertLogo, this.expertName, this.issueInfo});

  PlanFormDetail.fromJson(Map<String, dynamic> json) {
    expertFocus = json['expertFocus'];
    expertId = json['expertId'];
    expertLogo = json['expertLogo'];
    expertName = json['expertName'];
    issueInfo = json['planListIssue'] != null ? new IssueInfo.fromJson(json['planListIssue']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['expertFocus'] = this.expertFocus;
    data['expertId'] = this.expertId;
    data['expertLogo'] = this.expertLogo;
    data['expertName'] = this.expertName;
    if (this.issueInfo != null) {
      data['planListIssue'] = this.issueInfo!.toJson();
    }
    return data;
  }
}

class IssueInfo {
  int? buy;
  bool? canBuy;
  bool? canRead;
  int? issue;
  int? issueId;
  double? issueProfit;
  int? issueStage;
  int? issueState;
  List<IssueDetail>? issueDetail;
  String? matchTime;
  double? price;
  bool? purchased;
  int? pv;
  int? sportsId;
  int? state;
  double? profitMin;

  IssueInfo({this.buy, this.canBuy, this.canRead, this.issue, this.issueId, this.issueProfit, this.issueStage, this.issueState, this.issueDetail, this.matchTime, this.price, this.purchased, this.pv, this.sportsId, this.state});

  IssueInfo.fromJson(Map<String, dynamic> json) {
    buy = json['buy'];
    canBuy = json['canBuy'];
    canRead = json['canRead'];
    issue = json['issue'];
    issueId = json['issueId'];
    issueProfit = json['issueProfit'];
    issueStage = json['issueStage'];
    issueState = json['issueState'];
    if (json['list'] != null) {
      issueDetail = <IssueDetail>[];
      json['list'].forEach((v) { issueDetail!.add(new IssueDetail.fromJson(v)); });
      var stage = issueDetail?.where(
        (element) => element.stage == issueStage
      ).toList();
      if(stage.hasValue) profitMin = stage?.first.profitMin;
    }
    if(json['matchTime']!= null) {
      var time = DateTime.parse(json['matchTime']);
      if(time.isAfter(DateTime.now())){
        int value = time.day - DateTime.now().day;
        if(value == 0){
          matchTime = "今天${time.formatedString("HH:mm")}截止";
        }else if(value == 1){
          matchTime = "明天${time.formatedString("HH:mm")}截止";
        }else{
          matchTime = "${time.formatedString("dd HH:mm")}截止";
        }
      }else{
        matchTime = "已结束";
      }
    }
    price = json['price'];
    purchased = json['purchased'];
    pv = json['pv'];
    sportsId = json['sportsId'];
    state = json['state'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['buy'] = this.buy;
    data['canBuy'] = this.canBuy;
    data['canRead'] = this.canRead;
    data['issue'] = this.issue;
    data['issueId'] = this.issueId;
    data['issueProfit'] = this.issueProfit;
    data['issueStage'] = this.issueStage;
    data['issueState'] = this.issueState;
    if (this.issueDetail != null) {
      data['list'] = this.issueDetail!.map((v) => v.toJson()).toList();
    }
    data['matchTime'] = this.matchTime;
    data['price'] = this.price;
    data['purchased'] = this.purchased;
    data['pv'] = this.pv;
    data['sportsId'] = this.sportsId;
    data['state'] = this.state;
    return data;
  }
}

class IssueDetail {
  int? issueId;
  List<PlanItemShowEntity>? itemShow;
  List<MatchBries>? matchBries;
  String? matchTime;
  int? playType;
  double? profit;
  double? profitMin;
  int? stage;
  int? state;

  IssueDetail({this.issueId, this.itemShow, this.matchBries, this.matchTime, this.playType, this.profit, this.profitMin, this.stage, this.state});

  IssueDetail.fromJson(Map<String, dynamic> json) {
    issueId = json['issueId'];
    if (json['itemShow'] != null) {
      itemShow = <PlanItemShowEntity>[];
      json['itemShow'].forEach((v) { itemShow!.add(new PlanItemShowEntity.fromJson(v)); });
    }
    if (json['matchBries'] != null) {
      matchBries = <MatchBries>[];
      json['matchBries'].forEach((v) { matchBries!.add(new MatchBries.fromJson(v)); });
    }
    matchTime = json['matchTime'];
    playType = json['playType'];
    profit = json['profit'];
    profitMin = json['profitMin'];
    stage = json['stage'];
    state = json['state'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['issueId'] = this.issueId;
    if (this.itemShow != null) {
      data['itemShow'] = this.itemShow!.map((v) => v.toJson()).toList();
    }
    if (this.matchBries != null) {
      data['matchBries'] = this.matchBries!.map((v) => v.toJson()).toList();
    }
    data['matchTime'] = this.matchTime;
    data['playType'] = this.playType;
    data['profit'] = this.profit;
    data['profitMin'] = this.profitMin;
    data['stage'] = this.stage;
    data['state'] = this.state;
    return data;
  }
}